import Vue from "vue";
import App from "./App";
import router from "./router";
import Antd from "ant-design-vue";
import "ant-design-vue/dist/antd.css";
import store from "./store";
import "@/icons";
import md5 from "js-md5";
import echarts from "echarts";
Vue.prototype.$echarts = echarts;
Vue.config.productionTip = false;
Vue.use(Antd);
Vue.prototype.$md5 = md5;
router.beforeEach((to, form, next) => {
  // debugger
  if (to.path != "/login") {
    if (sessionStorage.getItem("userId")) {
      if (to.matched.length > 0) {
        let txt = "";
        for (var i in to.matched) {
          txt += to.matched[i].meta.title + " / ";
        }
        txt = txt.substring(0, txt.length - 2);
        store.commit("CHECKED_MENU", txt);
      }
      next();
    } else {
      next({
        path: "/login"
      });
    }
  } else {
    next();
  }

  // console.log(to)
});

new Vue({
  el: "#app",
  router,
  store,
  components: { App },
  template: "<App/>"
});
